package com.ht.shop.controller;

import com.alibaba.druid.util.StringUtils;
import com.ht.shop.service.UserService;
import com.ht.shop.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/active")
public class ActiveServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String code = req.getParameter("code");
        resp.setContentType("text/html;charset=utf-8");
        if (StringUtils.isEmpty(username)||StringUtils.isEmpty(code)) {
            resp.getWriter().write("参数呢？");
            return;
        }
        try {
            int active = userService.active(username, code);
            if (active == 1) {
                resp.getWriter().write("激活成功，请开启照骗之路");
            }else{
                resp.getWriter().write("激活失败，再重新试试，快点着急");
            }
        } catch (Exception e) {
            e.printStackTrace();
            resp.sendRedirect("/error/error.jsp");
        }

    }
}
